package com.klxedu.ms.gateway.security.authentication.impl;

import com.klxedu.ms.gateway.core.json.BaseJsonObject;
import com.klxedu.ms.gateway.security.client.UserFeignClient;
import com.klxedu.ms.gateway.security.client.service.LoginUser;
import com.klxedu.ms.gateway.utils.SpringBeanUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class WxOpenidAuthenticateAction extends AbstraAuthenticateAction {

    @Override
    BaseJsonObject<LoginUser> getLoginUser(String login) {
        UserFeignClient userFeignClient = SpringBeanUtils.getBean(UserFeignClient.class);
        BaseJsonObject<LoginUser> baseJsonObject = userFeignClient.getUserByWxOpenid("", login);
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        if(baseJsonObject.getData() != null){
        	baseJsonObject.getData().setPasswd(encoder.encode(DigestUtils.md5Hex(login)));
        }
        return baseJsonObject;
    }

}
